﻿using LS.Infrastructure.DbAccess;
using LS.Infrastructure.EntityExtension;
using QInfrastructure.Interfaces;
using QInfrastructure.Models;
using QInfrastructure.Models.SystemManager;
using QInfrastructure.Services.QDbContext;

namespace QInfrastructure.Services;




#nullable disable



public abstract class QBaseMainContext<TContext> : TService where TContext : ServiceHostDbContext, new()
{

     public SystemUser CurrentUser { get; set; }
    /// <summary>
    /// 登录用户Id
    /// </summary>
    public Guid LoginUserId { get; set; }
   
}

public class QBaseMainService: QBaseMainContext<MySqlDbContext>
{

    

    protected MySqlDbContext CreateContext(bool IsReadOnly = false)
    {
        return new MySqlDbContext(IsReadOnly);
    }

    protected PageQueryResult<T> GetPageQueryResultFromDb<T, C>(IQueryable<T> query, PageQueryParam<C> queryParams) where T : class, new() where C : class, new()
    {
        var res = new PageQueryResult<T>();
        res.pagesize = queryParams.pagesize;
        res.pageindex = queryParams.pageindex;
        res.total = query.Count();
        var datas = new List<T>();
        if (queryParams.pageindex > 0 && queryParams.pagesize > 0) datas = query.Skip((queryParams.pageindex - 1) * queryParams.pagesize).Take(queryParams.pagesize).ToList();
        else
        {
            datas = query.ToList();
        }
        res.rows = datas;
        return res;
    }





}